package com.example.behaviordemo.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/**
 * author : king_nina
 * e-mail : 13450414852@163.com
 * date   : 2021/12/2
 * desc   :
 */
open class ListPagerAdapter : FragmentPagerAdapter {

    private var fragmentList: MutableList<Fragment> = ArrayList()
    private var fragmentManager: FragmentManager? = null

    constructor(fm: FragmentManager, fragments: List<Fragment>?) : super(
        fm,
        BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
    ) {
        fragmentManager = fm
        fragmentList.clear()
        if (fragments != null) {
            fragmentList.addAll(fragments)
        }
    }

    override fun getItemPosition(`object`: Any): Int {
        return POSITION_NONE
    }

    override fun getCount(): Int {
        return fragmentList.size
    }

    override fun getItem(position: Int): Fragment {
        return fragmentList.get(position)
    }
}